import java.util.Scanner;
import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description: 进制转换
 */
public class Test2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int M = sc.nextInt();
        int N = sc.nextInt();
        //判断M为0的情况
        if(M == 0) {
            System.out.print(0);
        }
        boolean flg = true;
        //判断为负数的情况
        if(M < 0) {
            flg = false;
            M = -M;
        }
        Stack<Character> stack = new Stack<>();
        while(M != 0) {
            int tmp = M % N;
            if(tmp < 10) {
                stack.push((char)(tmp + '0'));
            }else {
                stack.push((char)(tmp - 10 + 'A'));
            }
            M /= N;
        }
        if(!flg) {
            System.out.print("-");
        }
        while(!stack.empty()) {
            System.out.print(stack.pop());
        }
    }
}
